home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1990 / Jan 90 / MacApp.Tech$ 1⁄19⁄90 / 0452-R» ISO Failures (lon-Jan90 < prev    next >
Encoding:
Text File  |  1991-03-06  |  3.4 KB  |  151 lines  |  [TEXT/GEOL]

  1. Item    2613680                         18-Jan-90        02:08
  2.  
  3. From:   CDA0004                         VAR Shana Corp, Don Murphy
  4.  
  5. To:     AUST0134                        Jam Software Sydney
  6.         MACAPP.TECH$                    MacApp Technical
  7.  
  8. Sub:    R» ISO Failures (long)
  9.  
  10. Attn: Tseung Cheung
  11. Attn: MacApp Technical
  12. SentBy: Wayne Malkin
  13. Date   1/17/90
  14. Subject    R» ISO Failures (long)
  15. From   Wayne Malkin
  16. To Tseung Cheung
  17.    MacApp Technical
  18.  
  19.  Memo         Subject:R» ISO Failures (long)
  20. Tseung,
  21.  
  22. Your error handling scheme looks all right (from an Inside Out perspective),
  23. except for one point. All though I haven't tried it, I suspect that calling
  24. Failure to drop out of an Inside Out error handler is VERY NASTY!
  25.  
  26. If you call Failure from within the Inside Out error handler, you are EXIT'ing
  27. everything out to your nearest MacApp failure handler, which bypasses all the
  28. pending code in Inside Out. This leaves Inside Out globals in an inconsistent
  29. state, which bodes ill for any future calls to Inside Out.
  30.  
  31. Generally I would say don't cause a MacApp failure directly out of an Inside
  32. Out error handler. Instead, write a little routine to signal a MacApp failure
  33. after the Inside Out call returns. You can write one which fails on any Inside
  34. Out error, and one which traps unexpected errors which you can filter in a
  35. local error handler.
  36.  
  37.  
  38. VAR
  39.   gISOErr : Integer;  { Initialize to 0 somewhere }
  40.  
  41.  
  42. PROCEDURE FailUnexpected;
  43. { Fails if an unexpected Inside Out error is not trapped in a local
  44.   error handler. }
  45. BEGIN
  46.   IF gISOErr <> noErr THEN
  47.     Failure (gISOErr);
  48. END;
  49.  
  50.  
  51. PROCEDURE FailInsideOut;
  52. { Fails on any Inside Out error }
  53. VAR
  54.   err : Integer;
  55. BEGIN
  56.   err := DBError;
  57.   IF err <> noErr THEN
  58.     Failure (err,0);
  59. END;
  60.  
  61.  
  62. So your global Inside Out error handler looks like this:
  63.  
  64.  
  65. FUNCTION MyDBErrorHandler (errCode : Integer; procName : tName) : Boolean;
  66. VAR
  67.   aBool : Boolean;
  68. BEGIN
  69.   { Display the error (I assume for debugging purposes) }
  70.   aBool := DBErrorHandler (errCode,procName);
  71.  
  72.   { Save it in a global for FailUnexpected }
  73.   gISOErr := errCode;
  74. END;
  75.  
  76.  
  77.  
  78. And, in a complex procedure:
  79.  
  80.  
  81. PROCEDURE TreadCarefully;
  82. VAR
  83.   pop : Boolean;
  84.   fi : FailInfo;
  85.  
  86.  
  87.   PROCEDURE FailureHandler (error : OSErr; message : LongInt);
  88.   BEGIN
  89.     IF pop THEN
  90.       DBPopError;
  91.     { clean up }
  92.   END;
  93.  
  94.  
  95.   FUNCTION ISOErrorHandler (errCode : Integer; procName : tName) : Boolean;
  96.   BEGIN
  97.     ISOErrorHandler := FALSE;
  98.     IF { errcode is something I expect } THEN
  99.       BEGIN
  100.         { Handle the error }
  101.         ISOErrorHandler := TRUE;
  102.       END;
  103.   END;
  104.  
  105.  
  106. BEGIN
  107.   pop := FALSE;
  108.   CatchFailures (fi,FailureHandler);
  109.  
  110. 1:
  111.   { Things which can fail }
  112.  
  113. 2:
  114.   { Inside Out calls which should fail }
  115.   SRInsert (theVw,@theRec);
  116.   FailInsideOut;
  117.  
  118. 3:
  119.   { Inside Out calls which should be trapped locally }
  120.   DBPushError (@ISOErrorHandler,@pop);
  121.   pop := TRUE;
  122.   IF SRNext (………) THEN
  123.     BEGIN
  124.     END;
  125.   FailUnexpected;
  126.  
  127. 4:
  128.   { Other things }
  129.   DBPopError;
  130.   pop := FALSE;
  131.  
  132.   Success (fi);
  133. END;
  134.  
  135.  
  136. Note that the Inside Out error handlers are NEVER popped unless you explicitly
  137. pop them, unlike the failure handlers in MacApp.
  138.  
  139. I hope this covers most of the cases you are trying to handle. Remember: don't
  140. fail from within an Inside Out error handler. You have to find some way to
  141. save the error, return to Inside Out, and fail just after the Inside Out call
  142. returns.
  143.  
  144. Regards,
  145.  
  146. Wayne Malkin
  147. Project Manager / Inside Out
  148. Shana Corporation
  149.  
  150.  
  151.